package it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.component.pawn.stats;

/** */
public class Stats {

	/** */
	static public final int TOTAL_STATISTICS = 7;
	
	/** */
	static public final int HEALTH = 0;
	
	/** */
	static public final int MOVEMENT_RANGE = 1;
	
	/** */
	static public final int ATTACK_RANGE = 2;
	
	/** */
	static public final int  PHYSICAL_FORCE = 3;
	
	/** */
	static public final int  MAGIC_FORCE = 4;
	
	/** */
	static public final int PHYSICAL_RESISTANCE = 5;
	
	/** */
	static public final int MAGIC_RESISTANCE = 6;
	
	/** */
	static public final String S_HEALTH = "Vita";
	
	/** */
	static public final String S_MOVEMENT_RANGE = "Movimento";
	
	/** */
	static public final String S_ATTACK_RANGE = "Raggio";
	
	/** */
	static public final String S_PHYSICAL_FORCE = "Attacco";
	
	/** */
	static public final String S_MAGIC_FORCE = "Magia";
	
	/** */
	static public final String S_MAGIC_RESISTANCE = "MR";
	
	/** */
	static public final String S_PHYSICAL_RESISTANCE ="Armatura";
	
	/** */
	static public String statsKeyString(final int key)
	{
		String string = null;
		switch (key) 
		{
		case HEALTH:
			string = S_HEALTH;
			break;
		case MOVEMENT_RANGE:
			string = S_MOVEMENT_RANGE;
			break;
		case ATTACK_RANGE:
			string = S_ATTACK_RANGE;
			break;
		case PHYSICAL_FORCE:
			string = S_PHYSICAL_FORCE;
			break;
		case MAGIC_FORCE:
			string = S_MAGIC_FORCE;
			break;
		case PHYSICAL_RESISTANCE:
			string = S_PHYSICAL_RESISTANCE;
			break;
		case MAGIC_RESISTANCE:
			string = S_MAGIC_RESISTANCE;
			break;
		}
		
		return string;
	}
	/** */
	protected float health;
	
	/** */
	protected float movementRange;
	
	/** */
	protected float attackRange;
	
	/** */
	protected float physicalForce;
	
	/** */
	protected float physicalResistance;
	
	/** */
	protected float magicForce;
	
	/** */
	protected float magicResistance;
	
	/** */
	public Stats()
	{
		health = movementRange = attackRange = physicalForce = magicForce = magicResistance = 0;
	}
	
	/** */
	public Stats(final Stats prototype)
	{
		copy(prototype);
	}
	
	public float getStats(final int key)
	{
		float result = -1;
		switch (key) 
		{
		case HEALTH:
			result = health;
			break;
		case MOVEMENT_RANGE:
			result = movementRange;
			break;
		case ATTACK_RANGE:
			result = attackRange;
			break;
		case PHYSICAL_FORCE:
			result = physicalForce;
			break;
		case MAGIC_FORCE:
			result = magicForce;
			break;
		case PHYSICAL_RESISTANCE:
			result = physicalResistance;
			break;
		case MAGIC_RESISTANCE:
			result = magicResistance;
			break;
		}
		return result;
	}
	/**
	 * @param prototype
	 */
	public void copy(final Stats prototype) 
	{
		health = prototype.health;
		movementRange = prototype.movementRange;
		attackRange = prototype.attackRange;
		physicalForce = prototype.physicalForce;
		magicForce = prototype.magicForce;
		physicalResistance = prototype.physicalResistance;
		magicResistance = prototype.magicResistance;
	}
	
	/** += */
	public Stats sum(final Stats stats, final boolean fake)
	{
		health += stats.health;
		attackRange += stats.attackRange;
		movementRange += stats.movementRange;
		magicForce += stats.magicForce;
		magicResistance += stats.magicResistance;
		physicalForce += stats.physicalForce;
		physicalResistance += stats.physicalResistance;
		
		return this;
	}
	
	public Stats subtract(final Stats stats)
	{
		health -= stats.health;
		attackRange -= stats.attackRange;
		movementRange -= stats.movementRange;
		magicForce -= stats.magicForce;
		magicResistance -= stats.magicResistance;
		physicalForce -= stats.physicalForce;
		physicalResistance -= stats.physicalResistance;
		
		return this;
	}
	
	
	/** Nuova stats sommata */
	public Stats sum(final Stats stats)
	{
		Stats tr = new Stats(stats);
		tr.sum(this, true);
		return tr;
	}
	
	/** */
	public Stats multiply(final Stats stats)
	{
		health *= stats.health;
		attackRange *= stats.attackRange;
		movementRange *= stats.movementRange;
		magicForce *= stats.magicForce;
		magicResistance *= stats.magicResistance;
		physicalForce *= stats.physicalForce;
		physicalResistance *= stats.physicalResistance;
		
		return this;
	}
	
	/** */
	public Stats multiply(final float number)
	{
		health *= number;
		attackRange *= number;
		movementRange *= number;
		magicForce *= number;
		magicResistance *= number;
		physicalForce *= number;
		physicalResistance *= number;
		
		return this;
	}
	/**Returns the health value. */
	public float getHealth() {
		return health;
	}
	
	/**Sets the health value.
	 * @param health 	is the new value */
	public void setHealth(float health) {
		this.health = health;
	}
	
	/**Returns the movement range value. */
	public float getMovementRange() 
	{
		System.out.println("character movement range "+movementRange);
		return movementRange;
	}
	
	/**Sets the movement range value.
	 * @param movementRange		is the new value */
	public void setMovementRange(float movementRange) {
		this.movementRange = movementRange;
	}
	
	/** */
	public float getAttackRange() {
		return attackRange;
	}
	
	/** */
	public void setAttackRange(float attackRange) {
		this.attackRange = attackRange;
	}
	
	/** */
	public float getPhysicalForce() {
		return physicalForce;
	}
	
	/** */
	public void setPhysicalForce(float physicalForce) {
		this.physicalForce = physicalForce;
	}
	
	/** */
	public float getMagicForce() {
		return magicForce;
	}
	
	/** */
	public void setMagicForce(float magicForce) {
		this.magicForce = magicForce;
	}
	
	/** */
	public float getPhysicalResistance() {
		return physicalResistance;
	}
	
	/** */
	public void setPhysicalResistance(float physicalResistance) {
		this.physicalResistance = physicalResistance;
	}
	
	/** */
	public float getMagicResistance() {
		return magicResistance;
	}
	
	/** */
	public void setMagicResistance(float magicResistance) {
		this.magicResistance = magicResistance;
	}
	
	public boolean setByIndex(int index, float value) {
		
		boolean result = true;
		
		switch (index) 
		{
		case HEALTH:
			health = value;
			break;
		case MOVEMENT_RANGE:
			movementRange = value;
			break;
		case ATTACK_RANGE:
			attackRange = value;
			break;
		case PHYSICAL_FORCE:
			physicalForce = value;
			break;
		case MAGIC_FORCE:
			magicForce = value;
			break;
		case PHYSICAL_RESISTANCE:
			physicalResistance = value;
			break;
		case MAGIC_RESISTANCE:
			magicResistance = value;
			break;
		default:
			result = false;
		}
		return result;
	}
	
	@Override
	public String toString() {
		
	return "HEALTH: "+health+"\n"+
	       "MOVEMENT RANGE: "+movementRange+"\n"+
		   "ATTACK RANGE: "+attackRange+"\n"+
	       "PHYSICAL FORCE: "+physicalForce+"\n"+
		   "MAGIC FORCE: "+magicForce+"\n"+
	       "PHYSICAL RESISTANCE: "+physicalResistance+"\n"+
		   "MAGIC RESISTANCE: "+magicResistance+"\n";
	}
}
